<?php



if (!function_exists('dr_son_url')) {
    function dr_son_url($data) {
        $config = \Phpcmf\Service::C()->get_cache('module-'.SITE_ID.'-quan', 'setting', 'param');;
        if (isset($config['son_rewrite']) && $config['son_rewrite'] && $config['son_rule']) {
            $mod = \Phpcmf\Service::C()->module;
            return \Phpcmf\Service::L('router')->get_url_value(
                $data,
                $config['son_rule'],
                \Phpcmf\Service::L('router')->url_prefix('rewrite', $mod, $data, 0)
            );
        }
        return '/index.php?s=quan&c=son&id='.$data['id'];
    }
}

// 是否存在中 1收藏了 2没有收藏
if (!function_exists('dr_is_son_cart')) {
    function dr_is_son_cart($dir, $id, $uid = 0)
    {

        !$uid && $uid = \Phpcmf\Service::C()->uid;
        if (!$uid) {
            return 0;
        } elseif (!$dir) {
            return 0;
        }

        return \Phpcmf\Service::M()->db->table(SITE_ID . '_' . $dir . '_cart')->where('uid', $uid)->where('cid', $id)->countAllResults();
    }
}

// 是否购买了
if (!function_exists('dr_is_son_buy')) {
    function dr_is_son_buy($dir, $id, $uid = 0)
    {

        !$uid && $uid = \Phpcmf\Service::C()->uid;
        if (!$uid) {
            return 0;
        } elseif (!$dir) {
            return 0;
        } elseif (!$id) {
            return 0;
        }

        return \Phpcmf\Service::M()->db->table(SITE_ID . '_' . $dir . '_buy')->where('uid', $uid)->where('cid', $id)->countAllResults();
    }
}
//默认添加会员组
function d_moren_huiyuanzu_add($data){
	
	//添加圈子普通会员组
	$yonghuzu = [
		'cid'=> $data['id'],
		'catid'=> $data['catid'],
		'uid'=> $data['uid'],
		'author'=> '',
		'inputip'=> $inputip,
		'inputtime'=> SYS_TIME,
		'title'=> '普通会员',
		'status'=> '1',
		'tableid'=> '0',
		'displayorder'=> '0',
		'updatetime'=> SYS_TIME,
		'fabutiezi'=> '1',
		'jifen'=> '10',
		'jingyan'=> '10',
		'huiyuanmoshi'=> '1', //会员模式
		'youxiaoqi'=> '0',
		'feiyong'=> '0.00',
		'tubiao'=> '',
		'ydqx'=> '1',
		'fabufufeitie'=> '0',
		'fbfjt'=> '0',
		'fbhdt'=> '0',
		'fbdst'=> '0',
		'fbspt'=> '0',
		'fbblt'=> '0',
		'fbtpt'=> '0',
		'fbsptz'=> '0',
		'fbsjt'=> '0',
		'fabuchuzutie'=> '0',
		'fbzpt'=> '0',
		'jiugetu'=> '1',
		'yuyin'=> '0',
		'shipin'=> '0',
		'mpsan'=> '0',
		'qiuzu'=> '0',
		'qiuzhi'=> '0',
		'kaiguan'=> '0',
		'leixing'=> '0',
		'bisai'=> '0',
		'caiji'=> '0',
	];
	\Phpcmf\Service::M()->db->table('1_quan_form_yonghuzu')->replace($yonghuzu);
	//添加附表
	$yonghuzufuid = \Phpcmf\Service::M()->db->insertID(); // id
	$datac = [
		'id'=> $yonghuzufuid,
		'cid'=> $data['id'], //类型
		'catid'=> $data['catid'], //类型
		'uid'=> $data['uid'], //发布人的uid
	];
	\Phpcmf\Service::M()->db->table('1_quan_form_yonghuzu_data_0')->replace($datac);
	
	//添加圈子铜牌卡员组
	$yonghuzu = [
		'cid'=> $data['id'],
		'catid'=> $data['catid'],
		'uid'=> $data['uid'],
		'author'=> '',
		'inputip'=> $inputip,
		'inputtime'=> SYS_TIME,
		'title'=> '铜牌卡',
		'status'=> '1',
		'tableid'=> '0',
		'displayorder'=> '0',
		'updatetime'=> SYS_TIME,
		'fabutiezi'=> '1',
		'jifen'=> '10',
		'jingyan'=> '10',
		'huiyuanmoshi'=> '2', //会员模式
		'youxiaoqi'=> '0',
		'feiyong'=> '10.00',
		'tubiao'=> '',
		'ydqx'=> '1',
		'fabufufeitie'=> '1',
		'fbfjt'=> '1',
		'fbhdt'=> '1',
		'fbdst'=> '1',
		'fbspt'=> '1',
		'fbblt'=> '1',
		'fbtpt'=> '1',
		'fbsptz'=> '1',
		'fbsjt'=> '1',
		'fabuchuzutie'=> '1',
		'fbzpt'=> '1',
		'jiugetu'=> '1',
		'yuyin'=> '1',
		'shipin'=> '1',
		'mpsan'=> '1',
		'qiuzu'=> '1',
		'qiuzhi'=> '1',
		'kaiguan'=> '1',
		'leixing'=> '0',
		'bisai'=> '1',
		'caiji'=> '1',
	];
	\Phpcmf\Service::M()->db->table('1_quan_form_yonghuzu')->replace($yonghuzu);
	//添加附表
	$yonghuzufuid = \Phpcmf\Service::M()->db->insertID(); // id
	$datac = [
		'id'=> $yonghuzufuid,
		'cid'=> $data['id'], //类型
		'catid'=> $data['catid'], //类型
		'uid'=> $data['uid'], //发布人的uid
	];
	\Phpcmf\Service::M()->db->table('1_quan_form_yonghuzu_data_0')->replace($datac);
	//添加圈子银牌卡员组
	$yonghuzu = [
		'cid'=> $data['id'],
		'catid'=> $data['catid'],
		'uid'=> $data['uid'],
		'author'=> '',
		'inputip'=> $inputip,
		'inputtime'=> SYS_TIME,
		'title'=> '银牌卡',
		'status'=> '1',
		'tableid'=> '0',
		'displayorder'=> '0',
		'updatetime'=> SYS_TIME,
		'fabutiezi'=> '1',
		'jifen'=> '20',
		'jingyan'=> '20',
		'huiyuanmoshi'=> '2', //会员模式
		'youxiaoqi'=> '0',
		'feiyong'=> '20.00',
		'tubiao'=> '',
		'ydqx'=> '1',
		'fabufufeitie'=> '1',
		'fbfjt'=> '1',
		'fbhdt'=> '1',
		'fbdst'=> '1',
		'fbspt'=> '1',
		'fbblt'=> '1',
		'fbtpt'=> '1',
		'fbsptz'=> '1',
		'fbsjt'=> '1',
		'fabuchuzutie'=> '1',
		'fbzpt'=> '1',
		'jiugetu'=> '1',
		'yuyin'=> '1',
		'shipin'=> '1',
		'mpsan'=> '1',
		'qiuzu'=> '1',
		'qiuzhi'=> '1',
		'kaiguan'=> '1',
		'leixing'=> '0',
		'bisai'=> '1',
		'caiji'=> '1',
	];
	\Phpcmf\Service::M()->db->table('1_quan_form_yonghuzu')->replace($yonghuzu);
	//添加附表
	$yonghuzufuid = \Phpcmf\Service::M()->db->insertID(); // id
	$datac = [
		'id'=> $yonghuzufuid,
		'cid'=> $data['id'], //类型
		'catid'=> $data['catid'], //类型
		'uid'=> $data['uid'], //发布人的uid
	];
	\Phpcmf\Service::M()->db->table('1_quan_form_yonghuzu_data_0')->replace($datac);
	//添加圈子金牌卡员组
	$yonghuzu = [
		'cid'=> $data['id'],
		'catid'=> $data['catid'],
		'uid'=> $data['uid'],
		'author'=> '',
		'inputip'=> $inputip,
		'inputtime'=> SYS_TIME,
		'title'=> '金牌卡',
		'status'=> '1',
		'tableid'=> '0',
		'displayorder'=> '0',
		'updatetime'=> SYS_TIME,
		'fabutiezi'=> '1',
		'jifen'=> '50',
		'jingyan'=> '50',
		'huiyuanmoshi'=> '2', //会员模式
		'youxiaoqi'=> '0',
		'feiyong'=> '50.00',
		'tubiao'=> '',
		'ydqx'=> '1',
		'fabufufeitie'=> '1',
		'fbfjt'=> '1',
		'fbhdt'=> '1',
		'fbdst'=> '1',
		'fbspt'=> '1',
		'fbblt'=> '1',
		'fbtpt'=> '1',
		'fbsptz'=> '1',
		'fbsjt'=> '1',
		'fabuchuzutie'=> '1',
		'fbzpt'=> '1',
		'jiugetu'=> '1',
		'yuyin'=> '1',
		'shipin'=> '1',
		'mpsan'=> '1',
		'qiuzu'=> '1',
		'qiuzhi'=> '1',
		'kaiguan'=> '1',
		'leixing'=> '0',
		'bisai'=> '1',
		'caiji'=> '1',
	];
	\Phpcmf\Service::M()->db->table('1_quan_form_yonghuzu')->replace($yonghuzu);
	//添加附表
	$yonghuzufuid = \Phpcmf\Service::M()->db->insertID(); // id
	$datac = [
		'id'=> $yonghuzufuid,
		'cid'=> $data['id'], //类型
		'catid'=> $data['catid'], //类型
		'uid'=> $data['uid'], //发布人的uid
	];
	\Phpcmf\Service::M()->db->table('1_quan_form_yonghuzu_data_0')->replace($datac);
	//添加圈子副管理员员组
	$yonghuzu = [
		'cid'=> $data['id'],
		'catid'=> $data['catid'],
		'uid'=> $data['uid'],
		'author'=> '',
		'inputip'=> $inputip,
		'inputtime'=> SYS_TIME,
		'title'=> '副管理员',
		'status'=> '1',
		'tableid'=> '0',
		'displayorder'=> '0',
		'updatetime'=> SYS_TIME,
		'fabutiezi'=> '1',
		'jifen'=> '100',
		'jingyan'=> '100',
		'huiyuanmoshi'=> '2', //会员模式
		'youxiaoqi'=> '0',
		'feiyong'=> '100.00',
		'tubiao'=> '',
		'ydqx'=> '1',
		'fabufufeitie'=> '1',
		'fbfjt'=> '1',
		'fbhdt'=> '1',
		'fbdst'=> '1',
		'fbspt'=> '1',
		'fbblt'=> '1',
		'fbtpt'=> '1',
		'fbsptz'=> '1',
		'fbsjt'=> '1',
		'fabuchuzutie'=> '1',
		'fbzpt'=> '1',
		'jiugetu'=> '1',
		'yuyin'=> '1',
		'shipin'=> '1',
		'mpsan'=> '1',
		'qiuzu'=> '1',
		'qiuzhi'=> '1',
		'kaiguan'=> '1',
		'leixing'=> '1',
		'bisai'=> '1',
		'caiji'=> '1',
	];
	\Phpcmf\Service::M()->db->table('1_quan_form_yonghuzu')->replace($yonghuzu);
	//添加附表
	$yonghuzufuid = \Phpcmf\Service::M()->db->insertID(); // id
	$datac = [
		'id'=> $yonghuzufuid,
		'cid'=> $data['id'], //类型
		'catid'=> $data['catid'], //类型
		'uid'=> $data['uid'], //发布人的uid
	];
	\Phpcmf\Service::M()->db->table('1_quan_form_yonghuzu_data_0')->replace($datac);
	\Phpcmf\Service::M()->db->table('1_quan')->where('id', $data['id'])->update([
		'yonghuzu_total' => '5',
	]);
	
}


